/*
 * CVIC.cpp
 *
 *  Created on: 05-06-2013
 *      Author: Sucharinho
 */

#include "CVIC.h"

void CVIC::InitFIQ(EIntSource source) {
	DisableInterrupts(1 << source);
	VICIntSelect |= (1 << source);
}

void CVIC::InitVectoredIRQ(EIntSource source, EPriority priority,
		void (*function)(void)) {

	volatile unsigned long* pVICVectCntl = &VICVectCntl0;
	volatile unsigned long* pVICVectAddr = &VICVectAddr0;

	DisableInterrupts(source);
	VICIntSelect &= ~((unsigned int) (source));

	unsigned int num = 0;
	//unsigned int temp = static_cast<unsigned int> (source);
	unsigned int temp = (unsigned int)(source);
	while (temp != 1) {
		temp  >>= 1;
		num++;
	}

	pVICVectCntl[num] = priority;
	pVICVectAddr[num] = (long unsigned int) function;
}
